//
//  MeatOrderDetailViewController.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/19.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatOrderDetailViewController.h"
#import "LogisticsViewController.h"


#import "GivingTableViewCell.h"
#import "MeatOrderBox.h"

#import "MeatOrderBodyCell.h"
#import "MeatOrderHeaderCell.h"
#import "MeatOrderFooterCell.h"
#import "MeatOrderLocationCell.h"
#import "MeatOrderDetailCell.h"


#import "MeatPayView.h"


@interface MeatOrderDetailViewController ()

@property (nonatomic, strong) MeatPayView *footer;


@end

@implementation MeatOrderDetailViewController


- (void)setupUI{
    
    {
        self.baseNavView.navTitleLabel.text = @"订单详情";
        self.baseNavView.navTitleLabel.textColor = KWhiteColor;
        
        [self.baseNavView.leftNavBtn setImage:[UIImage imageNamed:@"nav_white"] forState:UIControlStateNormal];
        
        UIImage *image = [UIImage imageNamed:@"meat_question_nav"];
        self.baseNavView.layer.contents =  (__bridge id)image.CGImage;
    }
    
    {
        [self.view addSubview:self.footer];
    }
    
}


- (void)setupLayout{
    
    self.footer.mj_y = self.view.bottom - _footer.height;
}


#pragma mark - networking methods
#pragma mark - response methods
#pragma mark - public methods

#pragma mark - tableview.delegate methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"点击tableView");
    
}


#pragma mark - tableview.datascource methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return section == 1 ?4 :1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==0) {
        return 90;
    }
    if (indexPath.section == 1) {
        switch (indexPath.row) {
            case 0:
                return 51;
                break;
            case 1:
                return 35;
                break;
            default:
                return 71;
                break;
        }
    }
    
    if (indexPath.section == 2) {
        return 110;
    }
    
    return 115;
}




- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return  [UIView new];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        MeatOrderLocationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeatOrderLocationCell"];
        cell.type = MeatOrderLocationCellType_Have;
        return cell;
    }
    
    if (indexPath.section == 1) {
        
        switch (indexPath.row) {
            case 0:
            {
                MeatOrderHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeatOrderHeaderCell"];
                cell.moreBtn.hidden = YES;
                
                cell.dealOperationBlock = ^{
                    
                };
                
                return cell;
            }
                break;
                
            case 1:
            {
                BaseIndentationTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeatOrderComments"];
                cell.textLabel.text = @"订单备注:请发货前先与我联系下";
                cell.textLabel.textColor = UIColorFromRGB(0x454545);
                cell.textLabel.font = mFont(13);
                return cell;
            }
                break;
                        
            default:
            {
                MeatOrderBodyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeatOrderBodyCell"];
                cell.backgroundColor = KRedColor;
                return cell;
                
            }
                break;
        }

    }
    
    
    MeatOrderDetailCell *newsCell = [tableView dequeueReusableCellWithIdentifier:@"MeatOrderDetailCell"];
    newsCell.type = indexPath.section == 2 ? MeatOrderDetailCellType_Source : MeatOrderDetailCellType_Settlement;
    return newsCell;
    
}

#pragma mark - setter methods

#pragma mark - getter methods

- (void)registerTableViewCell
{
    self.tableView.rowHeight = 186;
    self.tableView.height = KScreenHeight - TJ_NavBarHeight;
    self.tableView.mj_y = TJ_NavBarHeight;
    self.tableView.separatorColor = KClearColor;
    
    [self.tableView registerClass:[MeatOrderDetailCell class] forCellReuseIdentifier:@"MeatOrderDetailCell"];
    [self.tableView registerClass:[MeatOrderLocationCell class] forCellReuseIdentifier:@"MeatOrderLocationCell"];
    [self.tableView registerClass:[MeatOrderHeaderCell class] forCellReuseIdentifier:@"MeatOrderHeaderCell"];
    [self.tableView registerClass:[MeatOrderBodyCell class] forCellReuseIdentifier:@"MeatOrderBodyCell"];
    [self.tableView registerClass:[BaseIndentationTableCell class] forCellReuseIdentifier:@"MeatOrderComments"];

}

- (MeatPayView *)footer{
    
    if (!_footer) {
        _footer = [[MeatPayView alloc] init];
        _footer.type = MeatPayType_OrderDetail;
        
        //全选Block
        @weakify(self);
        _footer.chooseCartBlock = ^(UIButton *btn) {
            
        };
        
        //预留
        _footer.clearCartBlock = ^{
            @strongify(self);
            [[AlertAction sharedInstance] showAlertWithTitle:nil message:@"您确定要全部预留吗？，一经预留不可更改" confirmBtnTitle:@"确定" confirmBlock:^{
                // [self clearLoginAccount];
            } cancelBlock:nil];
        };
        
        //销售
        _footer.deleteCartBlock = ^{
            @strongify(self);
            LogisticsViewController *vc = [[LogisticsViewController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        };
    }
    return _footer;
}




@end


